﻿using System.Web.Mvc;
using CodeSaude.Application.Validation;

namespace CodeSaude.Web.Controllers
{
    public class BaseController : Controller
    {
        public ActionResult CreateResponse(ValidationApplicationResult result,
            object viewModelOnFail,
            string viewToRedirectOnSuccess) {
            if (!result.IsValid) {
                foreach (var erro in result.Erros) {
                    ModelState.AddModelError(string.Empty, erro);
                }
                return View(viewModelOnFail);
            }

            return RedirectToAction(viewToRedirectOnSuccess);
        }
    }
}